import { request } from '@/plugins/request'

// 获取公共文章列表
export const getArticles = params => {
  return request({
    method: 'GET',
    url: '/articles',
    params
  })
}

// 获取关注文章列表
export const getYourFeedArticles = params => {
  return request({
    method: 'GET',
    url: '/articles/feed',
    params,
  })
}

// 获取文章标签列表
export const getTags = () => {
  return request({
    method: 'GET',
    url: '/tags'
  })
}
// 添加点赞
export const addFavorite = slug => {
  return request({
    method: 'POST',
    url: `/articles/${slug}/favorite`
  })
}

// 取消点赞
export const deleteFavorite = slug => {
  return request({
    method: 'DELETE',
    url: `/articles/${slug}/favorite`
  })
}

// 获取文章详情
export const getArticle = slug => {
  return request({
    method: 'GET',
    url: `/articles/${slug}`
  })
}

// 获取文章评论
export const getComments = slug => {
  return request({
    method: 'GET',
    url: `/articles/${slug}/comments`
  })
}
// 添加文章评论
export const addComment = (slug, params) =>{
  return request({
    method: 'POST',
    url: `/articles/${slug}/comments`,
    data: params
  })
}
// 删除文章评论
export const deleteComment = (slug, id) =>{
  return request({
    method: 'DELETE',
    url: `/articles/${slug}/comments/${id}`,
  })
}

// 删除文章
export const deleteArticle = (slug)=>{
  return request({
    method: 'DELETE',
    url: `/articles/${slug}`,
  })
}
// 编辑文章
export const editorArticle = (slug, params)=>{
  return request({
    method: 'PUT',
    url: `/articles/${slug}`,
    data: params
  })
}
// 发布文章
export const createArticle = (params)=>{
  return request({
    method: 'POST',
    url: `/articles`,
    data: params
  })
}